# C:\Users\jason\AppData\Local\Android\Sdk\ndk\21.4.7075529\prebuilt\windows-x86_64\bin\gdb.exe
# tcp:192.168.160.138:4455
# C:/Users/jason/CLionProjects/EHomeBA330BurnIn/cmake-build-debug/EHomeBA330BurnIn

# -G "Ninja"  -DCMAKE_TOOLCHAIN_FILE="C:\Users\jason\AppData\Local\Android\Sdk\ndk\27.2.12479018\build\cmake\android.toolchain.cmake"  -DCMAKE_MAKE_PROGRAM="C:\Program Files\JetBrains\CLion 2024.3.2\bin\ninja\win\x64\ninja.exe" -DANDROID_ABI="arm64-v8a" -DANDROID_PLATFORM="android-30"

# C:\Users\jason\AppData\Local\Android\Sdk\build-tools\35.0.1
# C:\Users\jason\AppData\Local\Android\Sdk\ndk\27.2.12479018

cmake_minimum_required(VERSION 3.31)
project(EHomeBA330App)

set(CMAKE_CXX_STANDARD 17)

include_directories(.)
include_directories(include)
include_directories(include/ba330)

file(GLOB SRC_FILES
        src/serial/impl/list_ports/list_ports_linux.cc
        src/serial/impl/unix.cc
        src/serial/serial.cc
        src/BA330CameraManager.cpp
)

set(ANDROID_ABI "arm64-v8a")
set(ANDROID_PLATFORM "android-30")

set(AIDL_INPUT C:\\Users\\jason\\CLionProjects\\EHomeBA330BurnIn\\aidl\\com\\ehome\\ba330\\IBA330CameraService.aidl)
set(AIDL_OUTPUT_DIR C:\\Users\\jason\\CLionProjects\\EHomeBA330BurnIn\\aidl)

add_custom_command(
        OUTPUT ${AIDL_OUTPUT_DIR}/readme.md
        COMMAND rm -rf ${AIDL_OUTPUT_DIR}/com/ehome/ba330/*.cpp
        COMMAND rm -rf ${AIDL_OUTPUT_DIR}/com/ehome/ba330/*.h
        COMMAND C:/Users/jason/AppData/Local/Android/Sdk/build-tools/35.0.1/aidl.exe
        -oC:\\Users\\jason\\CLionProjects\\EHomeBA330BurnIn\\aidl
        -hC:\\Users\\jason\\CLionProjects\\EHomeBA330BurnIn
        -IC:\\Users\\jason\\CLionProjects\\EHomeBA330BurnIn\\aidl
        --lang=ndk
        ${AIDL_INPUT}
        COMMAND touch ${AIDL_OUTPUT_DIR}/readme.md
        COMMENT "Running AIDL NDK Code Generation Script"
        DEPENDS ${AIDL_INPUT}
)

add_custom_target(
        generate_aidl ALL
        DEPENDS ${AIDL_OUTPUT_DIR}/readme.md
)

file(GLOB AIDL_SRC_FILES
        aidl/com/ehome/ba330/*.cpp
)

add_library(ba330 STATIC
        ${SRC_FILES}
)

target_include_directories(ba330 PUBLIC
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/ba330>"
        "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

#foreach (item IN LISTS AIDL_SRC_FILES)
#    message(STATUS "########### Item: ${item}")
#endforeach ()

add_library(ba330_shared SHARED
        ${AIDL_SRC_FILES}
        main.cpp
)

target_link_libraries(ba330_shared
        log
        android
        binder_ndk
        ba330
)

add_executable(EHomeBA330BurnIn
        main.cpp
        ${AIDL_SRC_FILES}
)

add_dependencies(EHomeBA330BurnIn generate_aidl)

target_link_libraries(
        EHomeBA330BurnIn
        log
        android
        binder_ndk

        ba330
)

